//获取所有产品
export const getProductionLists = (data) => {
    return {type: 'GETPRODUCTIONLISTS', data}
}
export function fetchProductionLists(params) {
    return dispatch => {
        var url = 'http://localhost:3000/production/list';

        fetch(url, {method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body:params
    }).then(res => {
            return res.json()
        }).then(data => {
            dispatch(getProductionLists(data))
        })
    }
}
//获取商品分类
export const getProductionClassify = (data) => {
    return {type: 'GETPRODUCTIONCLASSIFY', data}
}
export function fetchProductionClassify() {
    return dispatch => {
        var url = 'http://localhost:3000/classify/list/3';

        fetch(url, {method: 'get'}).then(res => {
            return res.json()
        }).then(data => {
            dispatch(getProductionClassify(data))
        })
    }
}
//商品详情
export const getProductionDetail = (data) => {
    return {type: 'GETPRODUCTIONCDETAIL', data}
}
export function fetchProductionDetail(params) {
    return dispatch => {
        var url = 'http://localhost:3000/production/data/'+params;

        fetch(url, {method: 'get'}).then(res => {
            return res.json()
        }).then(data => {
            dispatch(getProductionDetail(data))
        })
    }
}
//获取分类名称
export const getProductionType = (data) => {
    return {type: 'GETPRODUCTIONTYPE', data}
}
export function fetchProductionType(params) {
    return dispatch => {
        var url = 'http://localhost:3000/classify/data/'+params;

        fetch(url, {method: 'get'}).then(res => {
            return res.json()
        }).then(data => {
            dispatch(getProductionType(data))
        })
    }
}